package com.fwlst.module_home.dialog;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.TextView;

import com.fwlst.module_home.R;


public class BaseLoadProgressDialog extends Dialog {
    private String message;
    private boolean canCancel;
    private TextView textView;
    @SuppressLint({"HandlerLeak"})
    private Handler handler;

    public BaseLoadProgressDialog(Context context, String message) {
        this(context, message, true);
    }

    public BaseLoadProgressDialog(Context context, String message, boolean canCancel) {
        super(context, R.style.BaseLoadProgressDialog);
        this.handler = new Handler() {
            public void handleMessage(Message msg) {
                if (msg.what == 0) {
                    BaseLoadProgressDialog.this.textView.setText(BaseLoadProgressDialog.this.message);
                }

            }
        };
        this.message = message;
        this.canCancel = canCancel;
    }

    public void setMessage(String message) {
        this.message = message;
        this.handler.sendEmptyMessage(0);
    }

    @SuppressLint({"ResourceType"})
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.base_load_dialog);
        this.textView = (TextView)this.findViewById(R.id.tv_message);
        this.setCanceledOnTouchOutside(this.canCancel);
        this.textView.setText(this.message);
    }
}
